package com.itheima.controller;




import com.itheima.entity.Result;
import com.itheima.pojo.Spec;
import com.itheima.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/spec")
@CrossOrigin
public class SpecController {
    @Autowired
    private SpecService specService;

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer curPage, @PathVariable("size") Integer size){
        return specService.findPage(curPage,size);
    }

    @PostMapping("/add")
    public Result add(@PathVariable Spec spec){
        return specService.add(spec);
    }

    @GetMapping("/{id}")
    public Result<Spec> findById(@PathVariable Integer id){
        return specService.findById(id);
    }

    @PutMapping("/{id}")
    public Result updateSpec(@PathVariable Spec spec){
        return specService.updateSpec(spec);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        return specService.deleteById(id);
    }
}
